home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / mac / developm / source / ncsat.cpt / Telnet2.5 final / main / prefs.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-04-05  |  12.9 KB  |  362 lines

  1. #ifdef lint
  2. static char *SCCSid = "%W%    (NCSA)    %G%";
  3. #endif
  4. /*
  5. *    prefs.c
  6. *     by Gaige B. Paulsen
  7. ****************************************************************************
  8. *    Part of NCSA Telnet for the Macintosh                                   *
  9. *                                                                          *
  10. *      Uses    :                                                               *
  11. *      TCP/IP kernel for NCSA Telnet                                       *
  12. *      by Tim Krauskopf                                                    *
  13. *       with Macintosh code by Gaige B. Paulsen                                 *
  14. *                                                                          *
  15. *      National Center for Supercomputing Applications                     *
  16. *      152 Computing Applications Building                                 *
  17. *      605 E. Springfield Ave.                                             *
  18. *      Champaign, IL  61820                                                *
  19. *                                                                          *
  20. *                                                                          *
  21. ****************************************************************************
  22. *
  23. *    Preferences reading,writing, and manipulating code.
  24. *
  25. *    Called by:
  26. *        menu.c
  27. *        maclook.c
  28. */
  29.  
  30. #include <StdIO.h>
  31. #include <String.h>
  32.  
  33. #include <Controls.h>
  34. #include <Dialogs.h>
  35. #include <Memory.h>
  36. #include <Resources.h>
  37.  
  38. #include "prefs.h"
  39. #include "configrec.h"
  40. #include "maclook.h"
  41. #include "menu.h"
  42. #include "event.h"
  43.  
  44. #ifdef MPW
  45. #include "mpw.h"
  46. #endif MPW
  47.  
  48. #define    DLOGOk        1
  49. #define DLOGCancel    2
  50.  
  51. #define    PrefDLOG    700        /* The Preferences Dialog        ---------------- */
  52. #define PrefOutline 3        /*   outline for OK */
  53. #define PrefCTt        5        /*   Copy table threshold */
  54. #define PrefCMDkey    6        /*   Command keys */
  55. #define PrefSave    7        /*     Save the Preferences */
  56. #define PrefBinary    8        /*   MacBinary active by default */
  57. #define PrefBReset    9        /*   Reset MacBinary to default at Beginning of FTP? */
  58. #define PrefOPTkey  10        /*     Remap option key to control */
  59. #define PrefTitle    11        /*      This is just a title */
  60. #define PrefDClose    12        /*      Don't close the window on "Close" */
  61. #define PrefTMap    13        /*     Shall we map the tilde? */
  62. #define PrefStag    14        /* Staggered Windows? */
  63. #define PrefBlink   15        /*   BYU 2.4.11 - Blink the cursor? */
  64. #define PrefBlockCursor           16    /* BYU 2.4.11 - Display a block cursor? */
  65. #define PrefUnderscoreCursor    17    /* BYU 2.4.11 - Display an underscore cursor? */
  66. #define PrefVerticalCursor        18    /* BYU 2.4.11 - Display a vertical line cursor? */
  67. #define PrefsysKCHR             19    /*   BYU 2.4.18 - Use system KCHR? */
  68.  
  69. extern SysEnvRec theWorld;        /* BYU 2.4.18 - System Environment record */
  70.  
  71. extern int whichMenus;        /* From Menu.c - which menu set is active */
  72. extern int MacBinary;        /* From Menu.c - is MacBinary active ? */
  73. extern int SettingsFile;    /* From Maclook.c - where is our resource file */
  74. extern int mapTilde;        /* From Event.c - are we currently mapping the tilde */
  75. extern short cursorBlink;    /* BYU 2.4.11 - From Event.c, are we blinking? */
  76. extern short cursorType;    /* BYU 2.4.11 - From Event.c, what kind of cursor? */
  77.  
  78. pascal void
  79.     VersionNumber(),        /* Version number display UI code */
  80.     OutlineItem();            /* Outline Item UI code */
  81. pascal int
  82.     modalProc();            /* Keep-alive proc */
  83.  
  84. /*
  85.  *  SavePrefs()    - puts the preferences record into the current resource file
  86.  *
  87.  */
  88. void SavePrefs
  89.   (
  90.     void
  91.   )
  92. {
  93.     NCSAPrefs *ppref, **hpref;
  94.  
  95.     if (SettingsFile == -1)
  96.         return;                /* Can't get it if there is no settings file */
  97.  
  98.     UseResFile(SettingsFile);
  99.  
  100.     hpref = (NCSAPrefs **) Get1Resource('NPRF',1);
  101.  
  102.     if (hpref==0L) {
  103.         (Handle) hpref = NewHandle( (long) sizeof(NCSAPrefs));
  104.         addresource((Handle) hpref, 'NPRF', 1, "Preferences");
  105.         }
  106.     else        /* The current handle may be too small, so fix it */
  107.         if ( ((int) GetHandleSize((Handle) hpref)) < sizeof(NCSAPrefs))
  108.             ReallocHandle((Handle) hpref, (long) sizeof(NCSAPrefs));
  109.  
  110.     HLock((Handle) hpref);
  111.         ppref = *hpref;
  112.         *ppref = Prefs;
  113.     HUnlock((Handle) hpref);
  114.  
  115.     ChangedResource((Handle) hpref);
  116.     UpdateResFile(SettingsFile);
  117. }
  118.  
  119. void PromptPrefs
  120.   (
  121.     void
  122.   )
  123. {
  124.     DialogPtr dtemp;
  125.     short dItem;
  126.     int tildeMap,dontclose, optKeys, cmdKeys,tempi,stag,sysKCHR,blink,curs;    /* BYU 2.4.18 */
  127.     Rect dBox;
  128.     Str255 temp, *tempp;
  129.     Handle CTtString, saveButton, CMDkeyCtrl, OPTkeyCtrl,
  130.             DCloseCtrl, MacBResetCtrl, MacBinaryCtrl, TMapCtrl, stagHndl,    /* BYU 2.4.11 */
  131.             sysKCHRCtrl,blinkCtrl, curs1Ctrl, curs2Ctrl, curs3Ctrl;            /* BYU 2.4.18 */
  132.     int MacBReset;
  133.  
  134.     tempp = (Str255 *) &temp;
  135.  
  136.     dtemp=GetNewDialog( PrefDLOG, (Ptr) 0L, (WindowPtr) -1L);    /* Bring on the box */
  137.     UItemAssign( dtemp, PrefOutline , (int (*)()) OutlineItem);
  138.  
  139.     if (SettingsFile == -1) {
  140.         GetDItem( dtemp, PrefSave, &dItem, &saveButton, &dBox);
  141.         HiliteControl((ControlHandle) saveButton, 255);
  142.         }
  143.     GetDItem( dtemp, PrefCTt, &dItem, &CTtString, &dBox);
  144.     GetDItem( dtemp, PrefCMDkey, &dItem, &CMDkeyCtrl, &dBox);
  145.     GetDItem( dtemp, PrefBinary, &dItem, &MacBinaryCtrl, &dBox);
  146.     GetDItem( dtemp, PrefBReset, &dItem, &MacBResetCtrl, &dBox);
  147.     GetDItem( dtemp, PrefOPTkey, &dItem, &OPTkeyCtrl, &dBox);
  148.     GetDItem( dtemp, PrefDClose, &dItem, &DCloseCtrl, &dBox);
  149.     GetDItem( dtemp, PrefTMap,   &dItem, &TMapCtrl, &dBox);
  150.     GetDItem( dtemp, PrefStag,   &dItem, &stagHndl, &dBox);
  151.     GetDItem( dtemp, PrefsysKCHR,  &dItem, &sysKCHRCtrl, &dBox);        /* BYU 2.4.18 */
  152.     GetDItem( dtemp, PrefBlink,  &dItem, &blinkCtrl, &dBox);            /* BYU 2.4.11 */
  153.     GetDItem( dtemp, PrefBlockCursor,      &dItem, &curs1Ctrl, &dBox);    /* BYU 2.4.11 */
  154.     GetDItem( dtemp, PrefUnderscoreCursor, &dItem, &curs2Ctrl, &dBox);    /* BYU 2.4.11 */
  155.     GetDItem( dtemp, PrefVerticalCursor,   &dItem, &curs3Ctrl, &dBox);    /* BYU 2.4.11 */
  156.  
  157.     sprintf((char *) tempp, "%d", Prefs.CTthresh);    /* Make it editable */
  158.     setitext( CTtString, (char *) tempp );    /* Install it in the dialog */
  159.     SelIText( dtemp, PrefCTt, 0, 32767);
  160.  
  161.     if (theWorld.systemVersion < 0x0700)                        /* BYU 2.4.18 */
  162.         SetCtlValue((ControlHandle) OPTkeyCtrl, Prefs.optKeys);    /* BYU 2.4.18 - Set up the Check box */
  163.     else {                                                        /* BYU 2.4.18 */
  164.         SetCtlValue((ControlHandle) OPTkeyCtrl, 0);                /* BYU 2.4.18 - Set up the Check box */
  165.         HiliteControl((ControlHandle) OPTkeyCtrl, 255);            /* BYU 2.4.18 */
  166.     }                                                            /* BYU 2.4.18 */
  167.  
  168.     optKeys = Prefs.optKeys;
  169.     SetCtlValue((ControlHandle) CMDkeyCtrl, Prefs.cmdKeys);/* Set up the Check box */
  170.     cmdKeys = Prefs.cmdKeys;
  171.     SetCtlValue((ControlHandle) MacBinaryCtrl, Prefs.MacBinary);/* Set up the Check box */
  172.     MacBinary = Prefs.MacBinary;
  173.     SetCtlValue((ControlHandle) MacBResetCtrl, Prefs.MacBReset);/* Set up the Check box */
  174.     MacBReset = Prefs.MacBReset;
  175.     SetCtlValue((ControlHandle) DCloseCtrl, Prefs.dontclose);/* Set up the Check box */
  176.     dontclose = Prefs.dontclose;
  177.     SetCtlValue((ControlHandle) TMapCtrl, Prefs.mapTilde);/* Set up the Check box */
  178.     tildeMap = Prefs.mapTilde;
  179.     SetCtlValue((ControlHandle) stagHndl, Prefs.stag);/* Set up the Check box */
  180.     stag = Prefs.stag;
  181.     SetCtlValue((ControlHandle) sysKCHRCtrl, Prefs.systemKCHR);    /* BYU 2.4.18 */
  182.     sysKCHR = Prefs.systemKCHR;                                    /* BYU 2.4.18 */
  183.     SetCtlValue((ControlHandle) blinkCtrl, Prefs.cursorBlink);    /* BYU 2.4.11 */
  184.     blink = Prefs.cursorBlink;                                    /* BYU 2.4.11 */
  185.     switch (Prefs.cursorType) {                                    /* BYU 2.4.11 */
  186.         case 0:                                                    /* BYU 2.4.11 */
  187.             SetCtlValue((ControlHandle) curs1Ctrl, 1);            /* BYU 2.4.11 */
  188.             curs = 0;                                            /* BYU 2.4.11 */
  189.             break;                                                /* BYU 2.4.11 */
  190.         case 1:                                                    /* BYU 2.4.11 */
  191.             SetCtlValue((ControlHandle) curs2Ctrl, 1);            /* BYU 2.4.11 */
  192.             curs = 1;                                            /* BYU 2.4.11 */
  193.             break;                                                /* BYU 2.4.11 */
  194.         case 2:                                                    /* BYU 2.4.11 */
  195.             SetCtlValue((ControlHandle) curs3Ctrl, 1);            /* BYU 2.4.11 */
  196.             curs = 2;                                            /* BYU 2.4.11 */
  197.             break;                                                /* BYU 2.4.11 */
  198.         default:                                                /* BYU 2.4.11 */
  199.             SetCtlValue((ControlHandle) curs1Ctrl, 1);            /* BYU 2.4.11 */
  200.             curs = 0;                                            /* BYU 2.4.11 */
  201.             break;                                                /* BYU 2.4.11 */
  202.     }                                                            /* BYU 2.4.11 */
  203.  
  204.  
  205.     dItem=0;                                /* initially no hits */
  206.     while((dItem>2 && dItem !=PrefSave)
  207.                    || (dItem==0)) {                    /* While we are in the loop */
  208.         ModalDialog((ModalFilterProcPtr) modalProc,&dItem); /* and do our duty to the box */
  209.         if (dItem == PrefBinary) {
  210.             MacBinary=!MacBinary;
  211.             SetCtlValue((ControlHandle) MacBinaryCtrl, MacBinary);
  212.             }
  213.         if (dItem == PrefTMap) {
  214.             tildeMap=!tildeMap;
  215.             SetCtlValue((ControlHandle) TMapCtrl, tildeMap);
  216.             }
  217.         if (dItem == PrefDClose) {
  218.             dontclose=!dontclose;
  219.             SetCtlValue((ControlHandle) DCloseCtrl, dontclose);
  220.             }
  221.         if (dItem == PrefBReset) {
  222.             MacBReset=!MacBReset;
  223.             SetCtlValue((ControlHandle) MacBResetCtrl, MacBReset);
  224.             }
  225.         if ((dItem == PrefOPTkey) && (theWorld.systemVersion < 0x0700)) {    /* BYU 2.4.18 */
  226.             optKeys=!optKeys;
  227.             SetCtlValue((ControlHandle) OPTkeyCtrl, optKeys);
  228.             }
  229.         if (dItem == PrefCMDkey) {
  230.             cmdKeys=!cmdKeys;
  231.             SetCtlValue((ControlHandle) CMDkeyCtrl, cmdKeys);
  232.             }
  233.         if (dItem == PrefStag) {
  234.             stag =!stag;
  235.             SetCtlValue((ControlHandle) stagHndl, stag);
  236.             }
  237.         if (dItem == PrefsysKCHR) {                                    /* BYU 2.4.18 */
  238.             sysKCHR =!sysKCHR;                                        /* BYU 2.4.18 */
  239.             SetCtlValue((ControlHandle) sysKCHRCtrl, sysKCHR);        /* BYU 2.4.18 */
  240.             }                                                        /* BYU 2.4.18 */
  241.         if (dItem == PrefBlink) {                                    /* BYU 2.4.11 */
  242.             blink =!blink;                                            /* BYU 2.4.11 */
  243.             SetCtlValue((ControlHandle) blinkCtrl, blink);            /* BYU 2.4.11 */
  244.             }                                                        /* BYU 2.4.11 */
  245.         if (dItem == PrefBlockCursor) {                                /* BYU 2.4.11 */
  246.             curs = 0;                                                /* BYU 2.4.11 */
  247.             SetCtlValue((ControlHandle) curs1Ctrl, 1);                /* BYU 2.4.11 */
  248.             SetCtlValue((ControlHandle) curs2Ctrl, 0);                /* BYU 2.4.11 */
  249.             SetCtlValue((ControlHandle) curs3Ctrl, 0);                /* BYU 2.4.11 */
  250.             }                                                        /* BYU 2.4.11 */
  251.         if (dItem == PrefUnderscoreCursor) {                        /* BYU 2.4.11 */
  252.             curs = 1;                                                /* BYU 2.4.11 */
  253.             SetCtlValue((ControlHandle) curs1Ctrl, 0);                /* BYU 2.4.11 */
  254.             SetCtlValue((ControlHandle) curs2Ctrl, 1);                /* BYU 2.4.11 */
  255.             SetCtlValue((ControlHandle) curs3Ctrl, 0);                /* BYU 2.4.11 */
  256.             }                                                        /* BYU 2.4.11 */
  257.         if (dItem == PrefVerticalCursor) {                            /* BYU 2.4.11 */
  258.             curs = 2;                                                /* BYU 2.4.11 */
  259.             SetCtlValue((ControlHandle) curs1Ctrl, 0);                /* BYU 2.4.11 */
  260.             SetCtlValue((ControlHandle) curs2Ctrl, 0);                /* BYU 2.4.11 */
  261.             SetCtlValue((ControlHandle) curs3Ctrl, 1);                /* BYU 2.4.11 */
  262.             }                                                        /* BYU 2.4.11 */
  263.  
  264.         }
  265.  
  266.     if (dItem==DLOGCancel) {
  267.             DisposDialog( dtemp);
  268.             return;
  269.             }
  270.  
  271.     getitext( CTtString, (char *) tempp);
  272.     sscanf((char *) tempp, "%d", &tempi);
  273.     Prefs.CTthresh  = tempi;
  274.  
  275.     Prefs.cmdKeys=cmdKeys;                    
  276.     Prefs.MacBinary=MacBinary;
  277.     Prefs.MacBReset=MacBReset;
  278.     Prefs.optKeys=optKeys;
  279.     Prefs.dontclose=dontclose;
  280.     Prefs.mapTilde =tildeMap;
  281.     Prefs.stag = stag;
  282.     Prefs.systemKCHR = sysKCHR;        /* BYU 2.4.18 */
  283.     Prefs.cursorBlink = blink;        /* BYU 2.4.11 */
  284.     Prefs.cursorType = curs;        /* BYU 2.4.11 */
  285.  
  286.     if (theWorld.systemVersion < 0x0700) {    /* BYU 2.4.18 */
  287.         if (optKeys)
  288.             optionKeys();                /* Turn it on.... */
  289.         else 
  290.             optionKeysOff();            /* Turn it off.... */
  291.     }                                        /* BYU 2.4.18 */
  292.  
  293.     mapTilde = tildeMap;            /* Change the real variable */
  294.     cursorBlink = blink;            /* BYU 2.4.11 */
  295.     cursorType = curs;                /* BYU 2.4.11 */
  296.  
  297.     switchMenus( cmdKeys);
  298.     whichMenus=cmdKeys;
  299.  
  300.     if (dItem == PrefSave)
  301.         SavePrefs();
  302.     DisposDialog( dtemp);
  303. }
  304.  
  305. /*
  306.  *    GetPrefs()    - gets the current preferences from the 'NPRF' 1 resource.
  307.  *            assumes RSRC file has already been opened.  Returns 0 if everything
  308.  *            is wonderful and 1 if the resource doesn't exist or isn't the right
  309.  *            version.
  310.  *
  311.  */
  312. int GetPrefs
  313.   (
  314.     void
  315.   )
  316. {
  317.     NCSAPrefs *ppref, **hpref;
  318.     
  319.     Prefs.cmdKeys = whichMenus;    /* when we have a blank file, override default with config.tel */
  320.  
  321.     if (SettingsFile == -1)
  322.         return(-1);                /* Can't get it if there is no settings file */
  323.  
  324.     UseResFile( SettingsFile);
  325.     hpref=(NCSAPrefs **)GetResource('NPRF',1);        /* Get the resource */
  326.  
  327.     if (hpref==0L)
  328.         return(1);                                    /* Doesn't exist */
  329.  
  330.     ppref = *hpref;                                    /* BYU 2.4.20 - Get the pointer */
  331.     if (ppref->Version < PREF_Version)                                /* BYU 2.4.18 */
  332.         SetHandleSize((Handle) hpref,(size_t) PrefLength[PREF_Version]);    /* BYU 2.4.18 MPW */
  333.  
  334.     HLock((Handle) hpref);
  335.         if (ppref->Version < PREF_Version)
  336.             movmem( ppref, &Prefs, PrefLength[ ppref->Version]);    /* Coerce by using known lengths */
  337.         else     
  338.             Prefs = *ppref;                                            /* Get the data */
  339.  
  340.         Prefs.Version = PREF_Version;                    /* We are now current */
  341.     HUnlock((Handle) hpref);
  342.  
  343.     /* Set everything up that way.... */
  344.  
  345.     if (theWorld.systemVersion < 0x0700) {    /* BYU 2.4.18 */
  346.         if (Prefs.optKeys)
  347.             optionKeys();                /* Turn it on.... */
  348.         else 
  349.             optionKeysOff();            /* Turn it off.... */
  350.     } else                                    /* BYU 2.4.19 */
  351.         Prefs.optKeys = 0;                    /* BYU 2.4.19 */
  352.  
  353.     switchMenus( Prefs.cmdKeys);
  354.     whichMenus=Prefs.cmdKeys;        /* Exported Variables */
  355.     MacBinary=Prefs.MacBinary;
  356.     mapTilde = Prefs.mapTilde;            /* Change the real variable */
  357.     cursorBlink = Prefs.cursorBlink;    /* BYU 2.4.11 */
  358.     cursorType = Prefs.cursorType;        /* BYU 2.4.11 */
  359.  
  360.     return(0);
  361. }
  362.